package com.jjyd.crlp.controller;

import com.jjyd.crlp.interceptor.LoginInterceptor;
import com.jjyd.crlp.interceptor.dto.JWTDto;
import com.jjyd.crlp.model.base.ResultModel;
import com.jjyd.crlp.model.dto.mine.MineInfoDto;
import com.jjyd.crlp.model.dto.mine.ModificationUserInfoDto;
import com.jjyd.crlp.services.MineService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 我的信息模块
 */
@RestController
@RequestMapping("/mine")
@Api(description = "我的信息模块")
public class MineController {

    @Autowired
    private MineService mineService;

    /**
     * 用户取消收藏单词功能接口
     *
     * @return 返回收藏记录id
     */
    @GetMapping("/getInfo")
    @ApiOperation(value = "返回我的个人信息")
    public ResultModel<MineInfoDto> getInfo(JWTDto jwtDto) {
        Integer userId = LoginInterceptor.getUserId();
        MineInfoDto info = mineService.getInfo(userId);
        return new ResultModel<>(info);
    }


    /**
     * 修改用户信息
     * @param modificationUserInfoDto 用户的个人信息
     * @return 返回用户的id
     */
    @PostMapping("/modification")
    @ApiOperation(value = "修改用户信息")
    public ResultModel<Integer> modification(JWTDto jwtDto, ModificationUserInfoDto modificationUserInfoDto) {

        Integer userId = LoginInterceptor.getUserId();
        Integer id = mineService.modification(modificationUserInfoDto,userId);
        return new ResultModel<>(id);
    }

}
